import requests


def getAudio(savename,url):
    response = requests.get(url)
    # 检查请求是否成功
    if response.status_code == 200:
        # 打开本地文件并写入内容
        with open(savename, "wb") as file:
            file.write(response.content)
        print("音频文件已成功下载到本地。")
        return True
    else:
        print(f"下载失败，状态码: {response.status_code}")
        return False
    
def chattts(msg,audioname):
    res = requests.post('http://192.168.88.251:9966/tts',data={
    "text": msg,
    "prompt": "",
    "voice": "3333",
    "temperature": 0.3,
    "top_p": 0.7,
    "top_k": 20,
    "skip_refine": 0,
    "custom_voice": 0,
    "is_split": 1
    })
    print(res.json())
    url = res.json()['url']
    print(url)
    getAudio(audioname,url)

chattts('文本内容','1.wav')